<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="4" :xs="24">
        <!--财物分类-->
        <div class="head-container">
          <el-input v-model="classifyName" placeholder="请输入分类名称" clearable size="small" prefix-icon="el-icon-search"
            style="margin-bottom: 20px" />
        </div>
        <div class="head-container">
          <el-tree :data="classifyOptions" :props="defaultProps" :expand-on-click-node="false"
            :filter-node-method="filterNode" ref="tree"  @node-click="handleNodeClick" default-expand-all />
        </div>
      </el-col>
      <!--财物数据-->
      <el-col :span="20" :xs="24">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

          <!-- <el-form-item label="库位" prop="storeId">
            <treeselect v-model="queryParams.storeId" :options="storeOptions" :show-count="true"
              placeholder="请选择仓库" style="width: 500px;"/>
          </el-form-item> -->
          <el-form-item prop="areaId" label="库区">
              <el-select v-model="queryParams.areaId" placeholder="选择库区" style="width: 160px;">
                <el-option
                  v-for="item in storeAreaOptions"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
            <!-- <el-form-item prop="locatorId" label-width="30px" v-if="queryParams.areaId">
              <el-select v-model="queryParams.locatorId" placeholder="请选择库位" style="width: 120px;">
                <el-option
                  v-for="item in locatorOptions"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item> -->
            <!-- <el-form-item label="RFID" prop="rfid">
              <el-input v-model="queryParams.rfid" placeholder="请输入RFID" clearable size="small"
                @keyup.enter.native="handleQuery" />
            </el-form-item> -->
          <el-form-item label="编号" prop="pno">
            <el-input v-model="queryParams.pno" placeholder="搜索编号" clearable size="small" style="width:250px"
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="名称" prop="name">
            <el-input v-model="queryParams.name" placeholder="搜索名称" clearable size="small"
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <!-- <el-form-item label="状态" prop="status">
            <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
              <el-option v-for="dict in dict.type.oms_property_status" :key="dict.value" :label="dict.label"
                :value="dict.value" />
            </el-select>
          </el-form-item> -->
          <!-- <el-form-item label="删除标识" prop="delFlag">
              <el-select v-model="queryParams.delFlag" placeholder="请选择删除标识" clearable size="small">
                <el-option
                  v-for="dict in dict.type.sys_del_flag"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item> -->
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
              v-hasPermi="['oms:property:add']">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
              v-hasPermi="['oms:property:edit']">修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
              v-hasPermi="['oms:property:remove']">删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
              v-hasPermi="['oms:property:export']">导出</el-button>
          </el-col>
          <!-- <el-col :span="1.5">
            <el-button type="warning" plain icon="el-icon-takeaway-box" :disabled="multiple" size="mini" @click="handlePack"
              v-hasPermi="['oms:property:edit']">打包移交</el-button>
          </el-col> -->
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="propertyList" @selection-change="handleSelectionChange" border stripe>
          <el-table-column type="selection" width="55" align="center" fixed="left" />
          <el-table-column label="编号" prop="pno" width="260" fixed="left">
            <template slot-scope="scope">
              <el-link type="primary" @click="handleInfo(scope.row)">{{scope.row.pno}}</el-link>
            </template>
          </el-table-column>
          <el-table-column label="名称" prop="name" min-width="160" fixed="left"/>
          <el-table-column label="所属单位" prop="deptName"  width="220"/>
          <!-- <el-table-column label="一级分类" prop="classifyName" width="120"/> -->
         <!-- <el-table-column label="二级分类" prop="secondClassifyName" width="220"/>
          <el-table-column label="三级分类" prop="thirdClassifyName" width="150"/> -->
         <!-- <el-table-column label="仓库" prop="store" width="280"/> -->
          <el-table-column label="库区" prop="area"  width="180">
            <template slot-scope="scope">
              <span v-if="scope.row.area">{{scope.row.area}}</span>
              <span v-else>{{scope.row.custodianPlace}}</span>
            </template>
          </el-table-column>
          <el-table-column label="库位" prop="locator" width="160">
          <template slot-scope="scope">
              <span v-if="scope.row.locator">{{scope.row.locator}}</span>
              <span v-else>{{scope.row.warehouseLocation}}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column label="RFID" prop="rfid"  width="180"/> -->
          <!-- <el-table-column label="物品特征" prop="character" width="380"/> -->
          <!-- <el-table-column label="案件编号" prop="caseNo" /> -->
          <el-table-column label="分类" prop="secondClassifyName" width="220"/>
          <el-table-column label="入库数" align="center" prop="status" width="80">
            <template slot-scope="scope">
              <el-badge :value="scope.row.innums" :type="scope.row.innums > 0 ?'success':'info'" class="item"></el-badge>
            </template>
          </el-table-column>
          <el-table-column label="出库数" align="center" prop="status" width="80">
            <template slot-scope="scope">
              <el-badge :value="scope.row.outnums" type="info" class="item"></el-badge>
            </template>
          </el-table-column>
          <el-table-column label="处置数" align="center" prop="status" width="80">
            <template slot-scope="scope">
              <el-badge :value="scope.row.deals" :type="scope.row.deals > 0 ?'danger':'info'" class="item"></el-badge>
            </template>
          </el-table-column>
          <el-table-column label="调用数" align="center" prop="status" width="80">
            <template slot-scope="scope">
              <el-badge :value="scope.row.tnums" :type="scope.row.tnums > 0 ?'warning':'info'" class="item"></el-badge>
            </template>
          </el-table-column>
          <el-table-column label="归还数" align="center" prop="status" width="80">
            <template slot-scope="scope">
              <el-badge :value="scope.row.rnums" :type="scope.row.rnums > 0 ?'success':'info'" class="item"></el-badge>
            </template>
          </el-table-column>
          <el-table-column label="库存数" align="center" prop="status" width="80">
            <template slot-scope="scope">
              <el-badge :value="scope.row.nums" :type="scope.row.nums > 0 ?'primary':'info'" class="item"></el-badge>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="80">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-view" @click="handleInfo(scope.row)"
                v-hasPermi="['oms:property:list']">查看</el-button>
              <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                v-hasPermi="['oms:property:edit']">修改</el-button>
              <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                v-hasPermi="['oms:property:remove']">删除</el-button> -->
            </template>
          </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
          @pagination="getList" :page-sizes="[10, 20, 30, 50, 100]" />
      </el-col>
    </el-row>

    <!-- 添加或修改财物对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="880px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">

        <el-row :gutter="15">
          <el-col :span="8">
            <el-form-item label="物品编号" prop="pno">
              <el-input v-model="form.pno" placeholder="请输入物品编号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="物品名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="RFID" prop="rfid">
              <el-input v-model="form.rfid" placeholder="请输入RFID" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="20">
            <el-form-item label="分类">
              <el-row>
                <el-col :span="6" class="mr10">
                  <el-select v-model="form.classifyId" placeholder="请选择一级分类"
                  @change="getSecondClassify($event,1)"  clearable>
                    <el-option
                      v-for="item in classifyFirst"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    />
                  </el-select>
                </el-col>
                <el-col :span="8" v-if="form.classifyId" class="mr10">
                  <el-select v-model="form.secondClassifyId" placeholder="请选择二级分类"
                  @change="getThirdClassify($event,2)" clearable>
                    <el-option
                      v-for="item in classifySecond"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    />
                  </el-select>
                </el-col>
                <el-col :span="8" v-if="form.secondClassifyId && form.classifyId">
                  <el-select v-model="form.thirdClassifyId" placeholder="请选择三级分类" clearable>
                    <el-option
                      v-for="item in classifyThird"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    />
                  </el-select>
                </el-col>
              </el-row>
            </el-form-item>
          </el-col>
        </el-row>

       <el-row>
          <el-col>
            <el-form-item label="所在库位">
              <el-row>
                <el-col :span="10" class="mr10">
                  <treeselect v-model="form.belongStoreId" :options="storeOptions" :show-count="true"
                    placeholder="请选择仓库" />
                </el-col>
                <el-col :span="6" v-if="form.belongStoreId" class="mr10">
                  <el-select v-model="form.areaId" placeholder="请选择库区">
                    <el-option
                      v-for="item in storeAreaOptions"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    />
                  </el-select>
                </el-col>
                <el-col :span="6" v-if="form.belongStoreId && form.areaId">
                  <el-select v-model="form.locatorId" placeholder="请选择库位">
                    <el-option
                      v-for="item in locatorOptions"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    />
                  </el-select>
                </el-col>
              </el-row>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="扣押单位">
              <treeselect v-model="form.officeId" :options="deptOptions" :show-count="true" placeholder="请选择单位"
               />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="所属单位">
              <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择单位"
                 />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="保管单位">
              <treeselect v-model="form.belongDeptId" :options="deptOptions" :show-count="true" placeholder="请选择单位"
               />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="8">
            <el-form-item label="办案民警">
              <el-input v-model="form.personName" placeholder="请输入办案民警" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="保管场所名称">
              <el-input v-model="form.belongDeptName" placeholder="请输入保管场所名称" style="width: 220px;" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单位">
              <el-select v-model="form.unit" placeholder="请选择单位">
                <el-option v-for="dict in dict.type.oms_property_unit" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row :gutter="15">
          <el-col>
            <el-form-item label="物品特征" prop="character">
              <el-input v-model="form.character" type="textarea" placeholder="请输入物品特征" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-drawer :title="title" :visible.sync="drawer" :before-close="handleClose" size="70vw">
        <el-card>
          <el-tabs v-model="activeName">
            <el-tab-pane label="财物信息" name="0">
             <el-descriptions border :column="3" direction="vertical">
                 <el-descriptions-item label="编号">{{form.pno}}</el-descriptions-item>
                 <el-descriptions-item label="名称">{{form.name}}</el-descriptions-item>
                 <el-descriptions-item label="RFID">{{form.rfid}}</el-descriptions-item>
                 <el-descriptions-item label="分类">{{(form.classifyName?form.classifyName:'')+(form.secondClassifyName?'/'+form.secondClassifyName:'')+(form.thirdClassifyName?'/'+form.thirdClassifyName:'')}}</el-descriptions-item>
                 <el-descriptions-item label="所属单位">{{form.deptName}}</el-descriptions-item>
                 <el-descriptions-item label="保管单位">{{form.transferName}}</el-descriptions-item>
                 <el-descriptions-item label="扣押单位">{{form.officeName}}</el-descriptions-item>
                 <el-descriptions-item label="办案民警">{{form.personName}}</el-descriptions-item>
                 <el-descriptions-item label="保管场所">{{form.store?form.store:form.custodianPlace}}</el-descriptions-item>
                 <el-descriptions-item label="库区库位" v-if="form.warehouseLocation">{{form.warehouseLocation}}</el-descriptions-item>
                 <el-descriptions-item label="物品特征" :span="3" v-if="form.character">{{form.character}}</el-descriptions-item>
             </el-descriptions>
              <el-card class="box-card" style="margin-top: 5px;" v-if="form.oss != null && form.oss.length > 0">
                   <div slot="header" class="clearfix">
                     <span>图片附件</span>
                   </div>
                   <div class="text item">
                     <!-- <el-image v-for="(pic,pindex) in form.oss"
                           style="width: 100px; height: 100px;margin-right: 5px;"
                           :src="pic.url"
                           fit="scale-down"
                           :preview-src-list="srcList"></el-image> -->
                       <!-- <el-image
                         style="width: 120px; height: 60px;margin-right: 5px;" :src="ossTransfer(form.oss,'one')" fit="scale-down"
                         :preview-src-list="ossTransfer(form.oss,'list')"></el-image> -->
                         <el-image v-if="form.oss && form.oss.length > 0" v-for="(pic,pindex) in form.oss"
                         style="width: 120px; height: 60px;margin-right: 5px;" :src="ossTransferThumbnail(pic,'one')" fit="scale-down"
                         :preview-src-list="ossTransfer(form.oss,'list')"></el-image>
                   </div>
                 </el-card>
            </el-tab-pane>
            <el-tab-pane label="财物日志" name="1">
              <el-timeline>
                <template v-for="(activity, index) in propertyLogOptions">
                <el-timeline-item :timestamp="activity.logTime" placement="top" type="info">
                  <!-- <el-card shadow="hover"> -->
                    <!-- <el-divider content-position="left"><el-badge is-dot type="info"></el-badge></el-divider> -->
                    <el-descriptions :column="1" border :labelStyle="{width:'120px'}">
                      <!-- <el-descriptions-item label="操作时间">{{activity.createTime}}</el-descriptions-item> -->
                      <el-descriptions-item label="操作人">{{activity.operator}}</el-descriptions-item>
                      <el-descriptions-item label="操作内容">{{activity.content}}</el-descriptions-item>
                      <el-descriptions-item label="图片" v-if="activity.oss && activity.oss.length > 0">
                        <!-- <el-image
                          style="width: 120px; height: 60px;margin-right: 5px;" :src="ossTransfer(activity.oss,'one')" fit="scale-down"
                          :preview-src-list="ossTransfer(activity.oss,'list')"></el-image> -->
                          <el-image v-for="(pic,pindex) in activity.oss"
                          style="width: 120px; height: 60px;margin-right: 5px;" :src="ossTransferThumbnail(pic,'list')" fit="scale-down"
                          :preview-src-list="ossTransfer(activity.oss,'list')"></el-image>
                      </el-descriptions-item>
                    </el-descriptions>
                  <!-- </el-card> -->
                </el-timeline-item>
                </template>
                </el-timeline>
            </el-tab-pane>
          </el-tabs>
        </el-card>
    </el-drawer>
  </div>
</template>

<script>
  import {
    listProperty,
    getProperty,
    delProperty,
    addProperty,
    updateProperty,
    initPackBean
  } from "@/api/oms/property";
  import {
    listTask,
    getTask,
    delTask,
    addTask,
    updateTask
  } from "@/api/oms/task";
  import {listPropertyLog} from '@/api/oms/propertyLog'
  import {
    treeselect
  } from "@/api/system/dept";
  import {
    listClassify,
    classifyTreeselect
  } from "@/api/oms/classify";
  import {
    listStore,
    storeTreeselect
  } from "@/api/wms/store";
  import {
    storeAreas
  } from "@/api/wms/storeArea";
  import {
    contacts
  } from "@/api/oms/contacts";
  import {
    locatores
  } from "@/api/wms/locator";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import selectProperty from "@/components/SelectProperty/index.vue";
  export default {
    name: "Property",
    dicts: ['oms_property_status', 'sys_del_flag','oms_property_unit','oms_staging_type','transfer_status','oms_delivery_type','oms_property_type'],
    components: {
      Treeselect,
      selectProperty
    },
    data() {
      return {
        // 按钮loading
        buttonLoading: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        classifyName: undefined,
        // 财物表格数据
        propertyList: [],
        classifyOptions: [],
        srcList:[],
        deptOptions:[],

        //财物分类级联
        classifyFirst:[],
        classifySecond:[],
        classifyThird:[],

        storeOptions: [],
        storeAreaOptions: [],
        locatorOptions: [],

        contactsOptions:[],
        issued:true,

        propertyLogOptions:[],

        defaultProps: {
          children: "children",
          label: "label"
        },
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        drawer:false,
        activeName:0,
        packOpen:false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 100,
          name: undefined,
          pno: undefined,
          classifyId: undefined,
          rfid: undefined,
          locatorId: undefined,
          status: undefined,
          delFlag: undefined,
          storeId: undefined,
          areaId: undefined,
          secondClassifyId:undefined,
          thirdClassifyId:undefined,
        },
        // 表单参数
        form: {},
        taskForm:{},
        taskRules:{
          deptId: [{
            required: true,
            message: "寄件单位不能为空",
            trigger: "blur"
          }],
          name: [{
            required: true,
            message: "寄件人不能为空",
            trigger: "blur"
          }],
          tel: [{
            required: true,
            message: "联系方式不能为空",
            trigger: "blur"
          }],
          address: [{
            required: true,
            message: "地址不能为空",
            trigger: "blur"
          }],
          propertyType: [{
            required: true,
            message: "物证类型不能为空",
            trigger: "blur"
          }],
          delivery: [{
            required: true,
            message: "物流配送不能为空",
            trigger: "blur"
          }],
        },
        // 表单校验
        rules: {
          name: [{
            required: true,
            message: "物品名称不能为空",
            trigger: "blur"
          }],
          pno: [{
            required: true,
            message: "物品编号不能为空",
            trigger: "blur"
          }],
          classifyId: [{
            required: true,
            message: "分类ID不能为空",
            trigger: "blur"
          }],
        },
        nodes1:[],
        nodes2:[],
        nodes3:[],
        nodes4:[],
        nodes5:[],
        nodes6:[]
      };
    },
    watch: {
      // 根据名称筛选部门树
      classifyName(val) {
        this.$refs.tree.filter(val);
      },
      'form.belongStoreId':{
        handler(newVal, oldVal) {
          // this.form.areaId = undefined
          this.getAreaTreeselect(newVal)
        },
        deep: true,
        immediate: true
      },
      'form.areaId':{
        handler(newVal, oldVal) {
          // this.form.locatorId = undefined;
          this.getLocators(newVal)
        },
        deep: true,
        immediate: true
      },
      // 'queryParams.storeId':{
      //   handler(newVal, oldVal) {
      //     // this.queryParams.areaId = undefined
      //     this.getAreaTreeselect(newVal)
      //   },
      //   deep: true,
      //   immediate: true
      // },
      // 'queryParams.areaId':{
      //   handler(newVal, oldVal) {
      //     // this.queryParams.locatorId = undefined;
      //     this.getLocators(newVal)
      //   },
      //   deep: true,
      //   immediate: true
      // }
    },
    created() {
      this.getList();
      this.getTreeselect();
      this.getClassifyTreeselect();
      this.getStoreTreeselect();
      this.getAreaTreeselect();
      this.getFirstClassify(null,0);
    },
    methods: {
      /** 查询财物列表 */
      getList() {
        this.loading = true;
        listProperty(this.queryParams).then(response => {
          this.propertyList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },
      addDtl() {
        this.$refs.elDrawer.open()
      },
      dtlDel(scope) {
        let index = scope.$index;
        if (this.taskForm.items[index].id && this.taskForm.items[index].id != '') {
          this.taskForm.items[index].delFlag = '2';
        } else {
          this.taskForm.items.splice(index, 1)
        }
      },
      //获取选择后的财务数据
      handleSelected(array) {
        array.forEach(item => {
          item.delFlag = '0'
          item.id = undefined
          item.nums = '0'

          this.taskForm.items.push(item)
        })
      },
      getUserMobile(e) {
        let _this = this;
        this.contactsOptions.forEach(item => {
          if (item.id == e) {
            _this.taskForm.name = item.name;
            _this.taskForm.tel = item.tel;

            _this.taskForm.lng = item.lng;
            _this.taskForm.lat = item.lat;
            if(_this.taskForm.delivery == '0'){
              _this.taskForm.address = item.address;
            }
          }
        });
      },
      getContacts() {
        contacts({
          'deptId': this.form.deptId
        }).then(response => {
          this.contactsOptions = response.data
        })
      },
      radioChange(e){
        this.taskForm.address = undefined;
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      close(){
        this.packOpen = false;
        this.taskReset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          name: undefined,
          pno: undefined,
          classifyId: undefined,
          secondClassifyId:undefined,
          thirdClassifyId:undefined,
          rfid: undefined,
          locatorId: undefined,
          status: '0',
          createTime: undefined,
          createBy: undefined,
          updateTime: undefined,
          updateBy: undefined,
          delFlag: undefined,
          storeId: undefined,
          areaId: undefined,
          character:undefined,
          oss:[]
        };
        this.resetForm("form");
      },
      /** 查询分类下拉树结构 */
      getClassifyTreeselect() {
        classifyTreeselect().then(response => {
          this.classifyOptions = response.data;
        });
      },
      getFirstClassify(parentId,level){
        listClassify({'level':level,'parentId':parentId}).then(response=>{
          this.classifyFirst = response.data;
        })
      },
      getSecondClassify(parentId,level){
        listClassify({'level':level,'parentId':parentId}).then(response=>{
          this.classifySecond = response.data;
        })
      },
      getThirdClassify(parentId,level){
        listClassify({'level':level,'parentId':parentId}).then(response=>{
          this.classifyThird = response.data;
        })
      },

      getStoreTreeselect() {
        storeTreeselect().then(response => {
          this.storeOptions = response.data;
        });
      },
      getAreaTreeselect(id) {
        storeAreas({
          "storeId": id
        }).then(response => {
          this.storeAreaOptions = response.data;
        });
      },
      getLocators(id) {
        locatores({
          "areaId": id
        }).then(response => {
          this.locatorOptions = response.data;
        });
      },
      // 筛选节点
      filterNode(value, data) {
        if (!value) return true;
        return data.label.indexOf(value) !== -1;
      },
      // 节点单击事件
      handleNodeClick(data) {
          if(data.weight == 0){
            this.queryParams.classifyId = data.id;
            this.queryParams.secondClassifyId = undefined;
            this.queryParams.thirdClassifyId = undefined;
          }
          if(data.weight == 1){
            this.queryParams.secondClassifyId = data.id;
            this.queryParams.classifyId = undefined;
            this.queryParams.thirdClassifyId = undefined;
          }
          if(data.weight == 2){
            this.queryParams.thirdClassifyId = data.id;
            this.queryParams.secondClassifyId = undefined;
            this.queryParams.classifyId = undefined;
          }

        this.handleQuery();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加财物";
        this.form.classifyId = this.queryParams.classifyId;
        let storeId = this.queryParams.storeId;
        let areaId = this.queryParams.areaId;
        let locatorId = this.queryParams.locatorId;
        this.getStoreTreeselect();
        this.form.storeId = storeId;
        this.form.areaId = areaId;
        this.form.locatorId = locatorId;
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.loading = true;
        this.reset();
        const id = row.id || this.ids
        getProperty(id).then(response => {
          this.loading = false;
          this.form = response.data;
          this.open = true;
          this.title = "修改财物";

          if(this.form.classifyId){
            this.getSecondClassify(this.form.classifyId,1)
          }
          if(this.form.secondClassifyId){
            this.getThirdClassify(this.form.secondClassifyId,2)
          }

        }).finally(() => {
          this.getStoreTreeselect();
          this.getAreaTreeselect();
          this.getLocators();
        });
      },
      handleInfo(row){
        this.activeName = '0'
        this.reset();
         const id = row.id || this.ids
          getProperty(id).then(response=>{
             this.form = response.data;
             let srcList = [];
             if(this.form.oss && this.form.oss.length > 0){
              this.form.oss.forEach(function(pic){
                srcList.push(pic.url);
              })
             }
             this.srcList = srcList;
             this.drawer = true;
             this.title = '财物详情'
          })
          let nodes1 = [];
          let nodes2 = [];
          let nodes3 = [];
          let nodes4 = [];
          let nodes5 = [];
          let nodes6 = [];
          listPropertyLog({'pno':row.pno,'delFlag':'0'}).then(response=>{
            this.propertyLogOptions = response.rows;
            // this.propertyLogOptions.forEach(item => {
            //   if(item.node == "1"){nodes1.push(item);}
            //   if(item.node == "2"){nodes2.push(item);}
            //   if(item.node == "3"){nodes3.push(item);}
            //   if(item.node == "4"){nodes4.push(item);}
            //   if(item.node == "5"){nodes5.push(item);}
            //   if(item.node == "6"){nodes6.push(item);}
            // })
            // this.nodes1 = nodes1;
            // this.nodes2 = nodes2;
            // this.nodes3 = nodes3;
            // this.nodes4 = nodes4;
            // this.nodes5 = nodes5;
            // this.nodes6 = nodes6;
          })
      },
      handleClose(){
        this.drawer = false;
      },
      // 表单重置
      taskReset() {
        this.taskForm = {
          id: undefined,
          taskNo: undefined,
          type: '0',
          storeId: undefined,
          nums: 0,
          weight:0,
          volume:0,
          checker: undefined,
          checkTime: undefined,
          checkStatus: "0",
          remark: undefined,
          delivery: '0',
          deptId: undefined,
          status: '0',
          createTime: undefined,
          createBy: undefined,
          updateTime: undefined,
          updateBy: undefined,
          lng: undefined,
          lat: undefined,
          address: undefined,
          tel: undefined,
          name: undefined,
          delFlag: '0',
          items: []
        };
        this.resetForm("taskForm");
      },
      handlePack(row){
        this.taskReset();
        const ids = row.id || this.ids;
        this.packOpen = true;
        this.title = '入库申请'
        initPackBean(ids).then(response=>{
          this.taskForm = response.data;
          this.getContacts();
        })
      },
      submitTaskForm(){
        this.$refs["taskForm"].validate(valid => {
          if (valid) {
            this.buttonLoading = true;
            if (this.taskForm.id != null) {
              updateTask(this.taskForm).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.packOpen = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            } else {
              addTask(this.taskForm).then(response => {
                this.$modal.msgSuccess("移交成功");
                if(this.issued){
                  let id = response.data.id;
                  sendsTask(id)
                }
              }).finally(() => {
                this.packOpen = false;
                this.getList();
                this.buttonLoading = false;
              });
            }
          }
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.buttonLoading = true;
            if (this.form.id != null) {
              updateProperty(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            } else {
              addProperty(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除财物编号为"' + ids + '"的数据项？').then(() => {
          this.loading = true;
          return delProperty(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).finally(() => {
          this.loading = false;
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('oms/property/export', {
          ...this.queryParams
        }, `property_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
